﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using StyleMVVM;
using StyleMVVM.DependencyInjection;

namespace SimpleWeather.UnitTests
{
	public class BaseTestClass
	{
		protected bool registerMainApp = true;
		protected bool registerUnitTestAssebly = true;
		protected Bootstrapper bootstrapper;

		protected IDependencyInjectionContainer Container
		{
			get { return bootstrapper.Container; }
		}

		[TestInitialize]
		public void Setup()
		{
			bootstrapper = new Bootstrapper();

			bootstrapper.Container.Environment = ExportEnvironment.UnitTest;

			if (registerMainApp)
			{
				bootstrapper.Container.RegisterAssembly(
					typeof (App).GetTypeInfo().Assembly);
			}

			if (registerUnitTestAssebly)
			{
				bootstrapper.Container.RegisterAssembly(
					GetType().GetTypeInfo().Assembly);
			}

			bootstrapper.Start();
		}

		[TestCleanup]
		public void Teardown()
		{
			bootstrapper.Shutdown();

			if (Bootstrapper.HasInstance)
				throw new Exception("bootstrapper did not cleanup");
		}
	}
}
